<div class="fsh-rightPanel">
    <div class="layui-anim layui-anim-upbit">
        <div class="layui-form-item wxmp-search" id="list_form">
            <div class="layui-inline" style="width: 250px">
                <input type="text" class="layui-input" id="bill_time" placeholder="选择对账日期">
                <i class="iconfont icon-rili"></i>
            </div>
            <div class="layui-inline">
                <button class="layui-btn btn-primary" id="search">对账</button>
            </div>
        </div>
        <table id="list_table" class="layui-hide" lay-filter="mainList"></table>
    </div>
</div>
<script>
    layui.use(['layer', 'table', "laydate"], function () {
        var layer = layui.layer;
        var table = layui.table;
        var laydate = layui.laydate;

        //日期选择
        laydate.render({
            elem: '#bill_time'
        });

        var tableObj = table.render({
            id: 'list_table',
            elem: '#list_table',
            url: '/payment/order/bill',
            where: {"bill_time": $("#list_form input[name='bill_time']").val() },
            method: "post",
            contentType: 'application/json',
            align: "center",
            cols: [[
                {field: 'mchOrderNo', title: '订单号'},
                {field: 'cardId', title: '卡号'},
                {field: 'cardOwner', title: '持卡人'},
                {field: 'amount', title: '金额(元)', align: 'center'},
                {
                    field: 'status', title: '状态', align: 'center', templet: function (d) {
                        if(d.status == 0)
                            return '订单生成';
                        else if(d.status == 1)
                            return '支付中';
                        else if(d.status == 2)
                            return '支付成功';
                        else if(d.status == 3)
                            return '处理完成';
                        else
                            return '未知';
                    }
                },
                {field: 'createTime', title: '创建时间', align: 'center'},
                {field: 'paySuccTime', title: '成功时间', align: 'center'},
                {field: 'wxOrderNo', title: '微信订单号', align: 'center'},
                {field: 'tradeTime', title: '交易时间', align: 'center'},
                {field: 'tradeStatus', title: '交易状态', align: 'center'},
                {field: 'bankCode', title: '付款银行编码', align: 'center'},
                {field: 'fee', title: '手续费', align: 'center'},
                {field: 'rate', title: '费率', align: 'center'},
                {
                    field: 'lock', title: '操作', align: 'center', templet: function (d) {
                        if(d.status != 2 && d.status != 3 && d.tradeStatus =='SUCCESS')
                            return '<a class="font-danger" lay-event="correct" href="javascript:;" > 补单</a>';
                    }
                }
            ]]
        });

        // 搜索
        $("#search").click(function () {
            reloadTable(tableObj);
        });

        //表格内部操作按钮监听
        table.on('tool(mainList)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'correct') {
                showConfirm("确认补单？", function () {
                    $.ajax({
                        url: '/payment/order/correct',
                        data: {"mchOrderNo": data.mchOrderNo},
                        success: function (result) {
                            if (result.success) {
                                layer.msg("补单成功");
                                reloadTable(tableObj);
                            } else {
                                layer.msg("补单失败");
                            }
                        }
                    })
                });
            }
        });
    });
</script>
